'''
pip3 install PyJWT
'''
import jwt
import hashlib
import uuid
import datetime

PRIVATE_KEY_ES256 ='''-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIFJ/dOWigk566LxRxdigvvwMNRuliciT7YGQyDOtK4UpoAoGCCqGSM49
AwEHoUQDQgAE+7pkc2KR0hWzZYD5yCLzo9HCjq4/37Du6s0ldOzfBJNJIM2hiLSq
V6TEoDNIBJuJqgjqSWjFVF3/tNcaMZUhlQ==
-----END EC PRIVATE KEY-----'''
ACode='AD-J4WR-XCXSW-HULB5-HUCLF-ZAA3J-W5RAR'

lic=hashlib.sha256(ACode.replace('-','').encode('utf-8')).hexdigest()
payload={
    "sub": "user@163.com",
    "iss": "user2@163.com",
    "nbf": int(datetime.datetime.timestamp(datetime.datetime.now() - datetime.timedelta(days=360))),
    "iat": int(datetime.datetime.timestamp(datetime.datetime.utcnow())),
    "exp": int(datetime.datetime.timestamp(datetime.datetime.now() + datetime.timedelta(hours=10))),#When to expire
    "aud": "DDAN",
    "jti": str(uuid.uuid4()).upper(),     #uuid
    "lic": [lic]  #hashlib.sha256(license).hexdigest()
    }
print(jwt.encode(algorithm='ES256',payload=payload,key=PRIVATE_KEY_ES256))
